package com.yupi.springbootinit.constant;

import lombok.Getter;

/**
 * 订单类型枚举
 */
@Getter
public enum OrderType {

    /**
     * 销售订单
     */
    SALES("SALES", "销售订单", "SO"),

    /**
     * 研发订单
     */
    RDO("RDO", "研发订单", "RDO");

    /**
     * 类型代码
     */
    private final String code;

    /**
     * 类型名称
     */
    private final String name;

    /**
     * 订单号前缀
     */
    private final String prefix;

    OrderType(String code, String name, String prefix) {
        this.code = code;
        this.name = name;
        this.prefix = prefix;
    }

    /**
     * 根据代码获取枚举
     */
    public static OrderType fromCode(String code) {
        for (OrderType type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知订单类型: " + code);
    }

    /**
     * 根据部门代码确定订单类型
     */
    public static OrderType fromDepartmentCode(String deptCode) {
        if (DepartmentConstants.SALES_DEPT.equals(deptCode)) {
            return SALES;
        } else if (DepartmentConstants.RD_DEPT.equals(deptCode)) {
            return RDO;
        }
        throw new IllegalArgumentException("该部门无权创建订单: " + deptCode);
    }
}